using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using Newtonsoft.Json;

public class Logins
{
    public string Name;
    public string pass;
}
public class ConFigMrg : SingLetion<ConFigMrg>
{
    public Dictionary<string, object> dic = new Dictionary<string, object>();

    public T GetTble<T>(string path) where T : class, new()//整个
    {
        if (dic.ContainsKey(path))
        {
            return dic[path] as T;
        }
        else
        {
            if (File.Exists(Application.dataPath + "/Resources/" + path + ".json"))
            {
                string json = Resources.Load<TextAsset>(path).text;
                T t = JsonConvert.DeserializeObject<T>(json);
                dic.Add(path, t);
                return t;
            }
            else
            {
                T t = new T();
                dic.Add(path, t);
                return t;
            }
        }
    }

    public T GetTDIc<T>(string path, int valus) where T : class, new() //路径  id单个
    {
        Dictionary<int, T> dicbuasl = GetTble<Dictionary<int, T>>(path);
        return dicbuasl[valus];
    }
    public void Save(string path, object obj)
    {
        Debug.Log(11);
        string json = JsonConvert.SerializeObject(obj);
        File.WriteAllText(Application.dataPath + "/Resources/" + path + ".json",json);
    }
}
